package com.example.listener;

import com.example.config.RabbitMQConfig;
import com.example.model.NotificationEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class NotificationEventListener {
    
    @RabbitListener(queues = RabbitMQConfig.NOTIFICATION_QUEUE)
    public void handleNotificationEvent(NotificationEvent event) {
        log.info("Received notification event: {}", event);
        
        // 处理通知事件的业务逻辑
        log.info("Sending notification to user: {}, channel: {}, message: {}", 
                event.getUserId(), event.getChannel(), event.getMessage());
        
        // 根据不同的通知渠道执行不同的发送逻辑
        switch (event.getChannel()) {
            case "EMAIL":
                sendEmail(event.getUserId(), event.getMessage());
                break;
            case "SMS":
                sendSms(event.getUserId(), event.getMessage());
                break;
            case "PUSH":
                sendPushNotification(event.getUserId(), event.getMessage());
                break;
            default:
                log.warn("Unknown notification channel: {}", event.getChannel());
        }
    }
    
    private void sendEmail(String userId, String message) {
        log.info("Sending email to user: {}, message: {}", userId, message);
        // 实际的邮件发送逻辑
    }
    
    private void sendSms(String userId, String message) {
        log.info("Sending SMS to user: {}, message: {}", userId, message);
        // 实际的短信发送逻辑
    }
    
    private void sendPushNotification(String userId, String message) {
        log.info("Sending push notification to user: {}, message: {}", userId, message);
        // 实际的推送通知逻辑
    }
} 